<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>积分明细</title>
    <link rel="stylesheet" href="https://www.layuicdn.com/layui-v2.5.6/css/layui.css" media="all">
    <style>
        .integral-container {
            padding: 20px;
        }

        td[data-field="imgUrl"] div,
        td[data-field="negativeImgUrl"] div {
            height: 120px;
        }

        .lay-form {
            padding: 20px;
        }

        .integral-container {
            background-color: #fff;
        }

        .bar {
            display: flex;
            justify-content: flex-start;
            align-items: flex-end;
        }

        .searchInput {
            display: flex;
            align-items: flex-end;
        }

        .searchInput label {
            font-size: 12px;
        }

        .searchInput input {
            width: 200px;
        }

    </style>
</head>

<body>
    <div class="integral-container">
        <!-- 搜索 -->
        <div class="searchInput">
            <form class="layui-form" action="" lay-filter="resets">
                <div class="layui-inline">
                    <label class="layui-form-label">客户手机：</label>
                    <input class="layui-input" name="userPhone" placeholder="请输入客户手机号" autocomplete="off">
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">变更日期：</label>
                    <input type="text" class="layui-input" id="test1" name="updateTime" placeholder="请输入变更日期"
                        autocomplete="off">
                </div>
                <button class="layui-btn" data-type="reload" lay-submit="" lay-filter="searchForm">搜索</button>
                <button class="layui-btn layui-btn-primary" data-type="reload" lay-submit=""
                    lay-filter="reset">重置</button>
            </form>
        </div>

        <table lay-filter="integralTable" class="layui-hide" id="integralTable"></table>
    </div>

</body>

<script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
<script src="../utils.js"></script>
<script>
    layui.use(['table', 'upload', 'form', 'jquery', "laydate"], function () {
        var table = layui.table,
            upload = layui.upload,
            form = layui.form,
            laydate = layui.laydate,
            $ = layui.jquery;

        table.render({
            elem: '#integralTable'
            , toolbar: "#toolbarDemo"
            , url: window.baseUrl + '/stat/getIntegralDetail'
            , headers: {
                Authorization: localStorage.token
            }
            , response: {
                statusCode: 200 //规定成功的状态码，默认：0
            }
            , cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
            , parseData: function (res) { //res 即为原始返回的数据
                return {
                    "code": 200,
                    "count": res.data.recordsTotal, //解析数据长度
                    "data": res.data.data //解析数据列表
                };
            }
            , request: {
                pageName: 'start' //页码的参数名称，默认：page
                , limitName: 'length' //每页数据量的参数名，默认：limit
            }
            , cols: [[
                { field: 'updateTime', title: '变更时间' }
                , { field: 'userPhone', title: '客户手机' }
                , { field: 'typeName ', title: '变更类型', templet: function(res) {
                    return res.typeName || "-"
                }}
                , { field: 'integral', title: '变更积分' }
                , { field: 'userTotalIntegral', title: '变更后积分', templet: function(res) {
                    return res.accountTotalIntegral || "-"
                }}
                , { field: 'des', title: '备注' }
            ]],
            page: true
            , done: function () {
        
            }
        });

        laydate.render({
            elem: '#test1'
        });

        // 搜索
        form.on("submit(searchForm)", function (e) {

            for (let key in e.field) {
                if (!e.field[key]) {
                    delete e.field[key]
                }
            }

            if (e.field.updateTime) {
                e.field.updateTime = new Date(e.field.updateTime)
            }

            table.reload('integralTable', {
                page: {
                    start: 1 //重新从第 1 页开始
                }
                , where: e.field
            });

            return false;
        })


        // 搜索
        form.on("submit(reset)", function (e) {

            table.reload('integralTable', {
                page: {
                    start: 1 //重新从第 1 页开始
                }
                , where: null
            });

            form.val("resets", {
                userPhone: "",
                updateTime: ""
            });

            return false;
        })

    });
</script>

</html>